package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.EmployeeAgreement;
import com.amsp.oa.oademo.service.EmployeeAgreementService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(tags = "员工协议书管理")
@RestController
@RequestMapping("/api/agreement")
public class EmployeeAgreementController {

    @Autowired
    private EmployeeAgreementService employeeAgreementService;

    @ApiOperation("分页查询员工协议书")
    @GetMapping("/page")
    public IPage<EmployeeAgreement> getPage(
            @ApiParam("当前页") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("员工姓名") @RequestParam(required = false) String employeeName,
            @ApiParam("部门/职务") @RequestParam(required = false) String departmentPosition) {
        return employeeAgreementService.getPage(current, size, employeeName, departmentPosition);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public EmployeeAgreement getById(@PathVariable Long id) {
        return employeeAgreementService.getById(id);
    }

    @ApiOperation("批量保存或更新")
    @PostMapping("/save")
    public boolean save(@RequestBody List<EmployeeAgreement> list) {
        return employeeAgreementService.saveOrUpdateBatch(list);
    }

    @ApiOperation("根据ID删除")
    @DeleteMapping("/{id}")
    public boolean removeById(@PathVariable Long id) {
        return employeeAgreementService.removeById(id);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/batch")
    public boolean removeBatchByIds(@RequestBody List<Long> ids) {
        return employeeAgreementService.removeByIds(ids);
    }
}